<?php

/**
 * 站点控制器
 */
class Controller_Site extends Controller_Abstract
{
    function actionIndex()
    {
       
    }

	
    function actionList(){
    
    	$page = $this->_context->param('page',1);
    	$page_size = $this->_context->param('row',10);
    	$list = Site::find()->asArray()->limitPage($page, $page_size)->getAll();
    	
    	return json_encode($list);
    
    }
    
    function actionNew(){
    	
    	$site = new Site($_POST);
    	
	    try {
	    	
	    	$site->save();
	    	
			return json_encode(array('success'=>true));
			
		} catch (QDB_ActiveRecord_ValidateFailedException $e) {			
			
			return json_encode(array('errorMsg' => $e->getMessage()));
			
		}
    }
    function actionUpdate(){
    	$id=$this->_context->post('site_id');
    	$site = Site::find('site_id=?',$id)->getOne();
    	
    	$site->changeProps($_POST);
    	
    	try{
    		$site->save();
    		return  json_encode(array('success'=>true));
    	}
    	catch (Exception $e){
    		return json_encode(array('errorMsg'=>'系统出错,操作未能完成.'));
    	}
    }
    
    function actionDestroy(){
    	
    	$id=$this->_context->post('id',0);
    	$row=Site::find("site_id=?",$id)->getOne();

    	try {
    		$row->destroy();
			return  json_encode(array('success'=>true));
    	}
    	catch (Exception $e){
				return json_encode(array('errorMsg'=>'系统出错,操作未能完成.'));
		}
    }
}

